//
//  Model.m
//  ProjectA
//
//  Created by lanouhn on 15/5/24.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "FirstModel.h"

@interface FirstModel ()

@end
@implementation FirstModel
-(void)dealloc {
    [_avatar release];
    [_uesrName release];
    [_duration release];
    [_url release];
    [_Num release];
    [_title release];
    [super dealloc];

}

+ (instancetype)modleWithDictionary:(NSDictionary *)dic{
    FirstModel *model = [[FirstModel alloc]init];
    model.avatar = dic[@"img"];
    model.uesrName = dic[@"username"];
    model.duration = dic[@"duration"];
    model.title = dic[@"title"];
    model.Num = dic[@"num"];
    model.url = dic[@"url"];
    model.created_at = dic[@"created_at"];
    return [model autorelease];

}
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.avatar forKey:@"avatar"];
    [aCoder encodeObject:self.uesrName forKey:@"uesrName"];
    [aCoder encodeObject:self.duration forKey:@"duration"];
    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.Num forKey:@"Num"];
    [aCoder encodeObject:self.url forKey:@"url"];
    [aCoder encodeObject:self.created_at forKey:@"created_at"];

    
}

//解码协议：是在反归档的时候将NSData类型的数据转成当前类的对象时调用的。解码时用到的key要跟编码时指定的key保持一致
- (id)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
       
        self.avatar = [aDecoder decodeObjectForKey:@"avatar"];
        self.uesrName = [aDecoder decodeObjectForKey:@"uesrName"];
        self.duration = [aDecoder decodeObjectForKey:@"duration"];
        self.title = [aDecoder decodeObjectForKey:@"title"];
        self.Num = [aDecoder decodeObjectForKey:@"Num"];
        self.url = [aDecoder decodeObjectForKey:@"url"];
        self.created_at = [aDecoder decodeObjectForKey:@"created_at"];
        

    }
    return self;
}
@end
